var wailianShare = function(links_id,end_time,title,iconurl,linkurl,sharetype) {
    var linkurl =linkurl.replace(new RegExp("&amp;","g"),"&");
    var obj = new Object();
    var userAgent = navigator.userAgent;
    var nowtime = Math.round(new Date().getTime()/1000).toString();
    var vendor = "Android";
    obj.init = function(){
        this.jsSafe();
        if (end_time > 1 && end_time < nowtime) {
            $("#public-web-container").html('<img class="error-images" src="https://nilife.oss-cn-beijing.aliyuncs.com/miniapp/images/setting/error.png"><p class="error-msg">会员已过期,请充值！</p>');
            return "会员已过期,请充值后重新生成！";
        }
        var mobile_flag = this.isMobile();
        var browserAgent = this.browserAgent();
        vendor = this.vendor();
        if(mobile_flag){
            if (browserAgent == "MicroMessenger") {
                window.location.href=linkurl;
            } else if (browserAgent == "baiduboxapp") {
                $("#timelinewechat").show().attr("onclick","bdShare();");
                $("#copywechat").hide();
                $(".wechat-addfriend-button-descript").html("点击立即前往微信；无需分享朋友圈直接点击链接即可！");
                this.bdShare();
            } else if (browserAgent == "QQBrowser") {
                $("#timelinewechat").show().attr("onclick","qqShare();");
                $("#copywechat").hide();
                $(".wechat-addfriend-button-descript").html("点击立即前往微信；无需分享朋友圈直接点击链接即可！");
                this.isloadqqApi();
                setTimeout(function(){ 
                    this.qqShare();
                },1000);
                this.qqShare(browserAgent);
            } else if (browserAgent == "UCBrowser") {
                $("#timelinewechat").show().attr("onclick","ucShare();");
                $("#copywechat").hide();
                $(".wechat-addfriend-button-descript").html("点击立即前往微信；无需分享朋友圈直接点击链接即可！");
                this.ucShare();
            } else {
                window.location.href="baiduboxapp://v1/easybrowse/open?url=https://bab.moreqifu.cn/l/"+links_id;
            }
        } else {
            console.log(mobile_flag);
        }
    }
    obj.vendor = function(){
        if (userAgent.search("Windows NT") != -1) {
            pvendor = "Windows";
        } else if (userAgent.search("iPhone") != -1) {
            pvendor = "iPhone";
        } else if (userAgent.search("iPad") != -1) {
            pvendor = "iPad";
        } else if (userAgent.search("Android") != -1) {
            pvendor = "Android";
        } else if (userAgent.search("Macintosh") != -1) {
            pvendor = "Mac";
        } else {
            pvendor = "Other";
        }
        return pvendor;
    }
    obj.browserAgent = function() {
        // 判断访问是什么设备
        if (userAgent.search('MicroMessenger') != -1) {
            // 微信浏览器
            browserAgent = "MicroMessenger";
        } else if(userAgent.search('QQBrowser') != -1 || userAgent.search('QQ/') != -1){
            // 电脑QQ浏览器
            browserAgent = "QQBrowser";
        } else if(userAgent.search('VivoBrowser') != -1){
            // Vivo浏览器
            browserAgent = "VivoBrowser";
        } else if(userAgent.search('HeyTapBrowser') != -1){
            // Oppo浏览器
            browserAgent = "HeyTapBrowser";
        } else if(userAgent.search('HuaweiBrowser') != -1){
            // 华为浏览器
            browserAgent = "HuaweiBrowser";
        } else if(userAgent.search('MiuiBrowser') != -1){
            // 小米浏览器
            browserAgent = "MiuiBrowser";
        } else if(userAgent.search('MQQBrowser') != -1){
            // QQ浏览器
            browserAgent = "MQQBrowser";
        } else if(userAgent.search('AlipayClient') != -1){
            // 支付宝浏览器
            browserAgent = "AlipayClient";
        } else if(userAgent.search('baiduboxapp') != -1){
            // 百度APP
            browserAgent = "baiduboxapp";
        } else if(userAgent.search('Weibo') != -1){
            // 微博浏览器
            browserAgent = "Weibo";
        } else if(userAgent.search('iqiyi') != -1){
            // 爱奇艺浏览器
            browserAgent = "iqiyi";
        } else if(userAgent.search('aweme') != -1){
            // 小米浏览器
            browserAgent = "aweme";
        } else if(userAgent.search('kdtUnion_iting') != -1){
            // 喜马拉雅
            browserAgent = "kdtUnion_iting";
        } else if(userAgent.search('DingTalk') != -1){
            // 钉钉
            browserAgent = "DingTalk";
        } else if(userAgent.search('UCBrowser') != -1 || userAgent.search('Quark') != -1){
            // UC浏览器
            browserAgent = "UCBrowser";
        } else if(userAgent.search('SamsungBrowser') != -1){
            // 三星浏览器
            browserAgent = "SamsungBrowser";
        } else if(userAgent.search('NokiaBrowser') != -1){
            // 诺基亚浏览器
            browserAgent = "NokiaBrowser";
        } else if(userAgent.search('Opera') != -1){
            // 欧朋
            browserAgent = "Opera";
        } else if(userAgent.search('Firefox') != -1){
            // 火狐
            browserAgent = "Firefox";
        } else if(userAgent.search('Zhihu') != -1 || userAgent.search('hihu') != -1){
            // 知乎
            browserAgent = "Zhihu";
        } else if(userAgent.search('LarkLocale') != -1){
            browserAgent = "Feishu";
        } else if(userAgent.search('iPhone') != -1){
            browserAgent = "iPhone";
        } else if(userAgent.search('iPad') != -1){
            browserAgent = "iPad";
        } else if(userAgent.search('Macintosh') != -1){
            browserAgent = "Mac";
        } else {
            browserAgent = "Other";
        }
        return browserAgent;
    }
    obj.isMobile = function() {
        if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|XiaoMi|IEMobile)/i)) {
            return true;
        } else {
            return false;
        }
    }
    obj.bdShare = function() {
        this.jsSafe();
        if (vendor == "iPhone" || vendor == "iPad") {
            var timestamp = Date.parse(new Date());
            var shareUrl = "baiduboxapp://callShare?" + ["options=" + encodeURIComponent(JSON.stringify({
                type: "url",
                mediaType: "weixin_timeline",
                iconUrl: iconurl,
                title: title,
                content: "百度分享",
                linkUrl: linkurl,
                shareSuccessCB: "shareSuccessCallback",
                shareErrorCB: "shareFailCallback"

            }))];
            shareUrl = shareUrl + "&minver=5.3.5.0&successcallback=shareSuccessCallback" + timestamp + "&errorcallback=shareFailCallback" + timestamp;
            location.href = shareUrl;
        } else if (vendor == "Android") {
            prompt("BdboxApp:" + JSON.stringify({
                obj: "Bdbox_android_utils",
                func: "callShare",
                args: ['{' +
                'imageUrl: "",' +
                'mediaType: "weixin_timeline",' +
                'title: "' + title +
                '",content: "' + "描述" +
                '",linkUrl: "' + linkurl +
                '",iconUrl: "' + iconurl + '" }',"window.NativeShareSuccessCallback", "window.NativeShareFailCallback"]
            }))
        }
    }
    obj.qqShare = function() {
        this.jsSafe();
        var config = {
            url:linkurl,
            title:title,
            desc:title,
            img:iconurl,
            img_title:title,
            from:'QQ浏览器'
        };
        var share_obj = new nativeShare('nativeShare',config);
    }
    obj.ucShare = function() {
        this.jsSafe();
        let platform = "";
        if (sharetype == "timeline") {
            if (vendor = "Android") {
                platform = "WechatTimeline";
            } else {
                platform = "kWeixinFriend";
            }
        } else {
            if (vendor = "Android") {
                platform = "kWeixin";
            } else {
                platform = "WechatFriends";
            }
        }
        let shareInfo = [title,"UC浏览器",linkurl,platform, '', '', '' ];
        if (window.ucweb) {
            ucweb.startRequest && ucweb.startRequest('shell.page_share', shareInfo);
        } else if (window.ucbrowser) {
            ucbrowser.web_share && ucbrowser.web_share.apply(null, shareInfo);
        }
    }
    obj.launchBaidu = function() {
        window.location.href="baiduboxapp://v1/easybrowse/open?url=https://anxins.cn/l/"+links_id;
    }
    obj.launchQQBrowser = function() {
        window.location.href="mttbrowser://url=https://anxins.cn/l/"+links_id;
    }
    // QQ浏览器
    obj.isloadqqApi = function() {
        var b = "https://wailiancn.oss-cn-beijing.aliyuncs.com/assets/js/v2/qqshare.js?versionId=CAEQFBiBgICQxYGq0xciIDAxZjM2ZjU5YzNkMjQwNGJhOTk3ZWI2ODMyZWUyZTQx";
        var d = document.createElement("script");
        var a = document.getElementsByTagName("body")[0];
        d.setAttribute("src", b);
        a.appendChild(d)
    }
    obj.jsSafe = function() {
        var urlhref = document.domain;
        var whiteurl = ["aixin7.cn", "ding7.cn", "wailian9.cn", "wailian1.cn", "wailian2.cn", "zk82.cn", "127.0.0.1", "anxins.cn", "lbexlit.cn", "larztsh.cn", "ili8g.cn","s.pdb2.com","b6s.cn""11dr.cn","d.pdd68.com","f.mpay8.cn","fss.mpay8.cn"];
        if (!whiteurl.includes(urlhref)) {
            console.error("同行您好: 本代码已加密,想用自己写吧！\n外链官网: https://nilife.cn\n非常感谢！");
            window.location.href="https://nilife.cn";
        }
    }
    return obj;  
}